# verify_move.py
import os
import sqlite3
from app import app

print("=== 验证数据库移动 ===")

# 检查新位置
new_db_path = os.path.join(os.path.abspath('.'), 'instance', 'site.db')
print(f"新数据库路径: {new_db_path}")
print(f"文件存在: {os.path.exists(new_db_path)}")

if os.path.exists(new_db_path):
    size = os.path.getsize(new_db_path)
    print(f"文件大小: {size} 字节")

    # 测试数据库内容
    try:
        conn = sqlite3.connect(new_db_path)
        cursor = conn.cursor()

        # 获取所有表
        cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
        tables = cursor.fetchall()

        print("数据库中的表:")
        for table in tables:
            print(f"  - {table[0]}")

        # 获取用户数据
        cursor.execute("SELECT username, email FROM user;")
        users = cursor.fetchall()

        print(f"用户数量: {len(users)}")
        for user in users:
            print(f"  - 用户名: {user[0]}, 邮箱: {user[1]}")

        conn.close()
        print("✅ 数据库移动成功且数据完整")

    except Exception as e:
        print(f"❌ 数据库测试失败: {e}")
else:
    print("❌ 数据库文件不存在")